package main

import (
"fmt"
"net"
"strconv"
	"time"
)

func main() {
	fmt.Println("udpClient")
	socket, err := net.DialUDP("udp4", nil, &net.UDPAddr{
		IP: net.IPv4(192, 168, 1, 211),
		Port: 7000,
	})
	if err != nil {
		fmt.Println("connect fail !", err)
		return
	}
	//defer socket.Close()


	var i int  = 0
	for {
		senddata := []byte(strconv.Itoa(i))
		fmt.Println("发送UDP数据！")
		_, err = socket.Write(senddata)
		if err != nil {
			fmt.Println("send fail !", err)
			return
		}
        time.Sleep(1*time.Microsecond)
		i++
	}
	data := make([]byte, 20)
	read, remoteAddr, err := socket.ReadFromUDP(data)
	if err != nil {
		fmt.Println("read fail !", err)
		return
	}
	fmt.Println(read, remoteAddr)
	fmt.Printf("%s\n", data)
}